﻿using Architecture.Domain.BankManagement.Mapping;
using Architecture.Domain.TestModel.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Architecture.Domain.BankManagement
{
    public class BankManagementContext : DbContext
    {
//        public BankManagementContext(String connectionStringName):base(String.Format("name={0}", connectionStringName))
        public BankManagementContext() : base("name=BankManagementContext")
        {
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            this.Configuration.AutoDetectChangesEnabled = false;
            this.Configuration.LazyLoadingEnabled = false;
            this.Configuration.ProxyCreationEnabled = false;

            Database.SetInitializer<BankManagementContext>(null);
            //Database.SetInitializer<LoggingServiceContext>(new DropCreateDatabaseIfModelChanges<LoggingServiceContext>());

        }

        public virtual DbSet<Compte> Comptes { get; set; }
        public virtual DbSet<Client> Clients { get; set; }
        public virtual DbSet<Country> Countries { get; set; }
        public virtual DbSet<Instrument> Instruments { get; set; }


        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            //Remove unused conventions
            modelBuilder.Conventions.Remove<OneToManyCascadeDeleteConvention>();

            //Add entity configurations in a structured way using 'TypeConfiguration’ classes
            modelBuilder.Configurations.Add(new CountryEntityConfiguration());
            modelBuilder.Configurations.Add(new CustomerEntityConfiguration());
            modelBuilder.Configurations.Add(new InstrumentEntityConfiguration());
            modelBuilder.Configurations.Add(new CompteEntityConfiguration());

            base.OnModelCreating(modelBuilder);
        }
    }
}
